package com.riant.day08;

/**
 * @Classname Demo02
 * @Description TODO
 * @Date 2021/3/24 10:09
 * @Created by 张斌
 */
public class Demo02 implements Runnable {
    private boolean flag=true;
    @Override
    public void run() {
        int i=0;
        while(flag){
            System.out.println("run ... thread"+i++);
        }
    }

    public void setFlag(boolean flag) {
        this.flag = flag;
    }

    public static void main(String[] args) {
        Demo02 demo02=new Demo02();
        new Thread(demo02).start();
        for(int i=0;i<950;i++){
            System.out.println("main"+i);
            if(i==900){
                demo02.setFlag(false);
                System.out.println("线程停止了");
            }
        }
    }
}
